/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Yi Dev, Ltd. All Right Reserved.
 * @address:     https://yiyuery.github.io/
 * @date:        2019/5/20 20:57
 * @email:       xiazhaoyang@live.com
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.example.common.util;

import com.example.common.enums.BasePathEnum;
import com.example.common.enums.EnvConfPathEnum;
import com.example.common.enums.OSNameEnum;
import lombok.Data;

import java.util.Arrays;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author Yi
 * @version v1.0.0
 * @date 2019-07-21 11:06
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2019-07-21
 * @modify reason: {方法名}:{原因}
 * ...
 */
@Data
public class RunnerMonitor {

    private static String osName;

    static {
        osName = System.getProperties().getProperty("os.name");
    }

    /**
     * 获取运行环境
     * @return
     */
    public static OSNameEnum getOSType(){
        return Arrays.stream(OSNameEnum.values()).filter(p->p.getOsName().equals(osName)).collect(Collectors.toList()).get(0);
    }

    /**
     * 获取系统配置文件路径
     * @return
     */
    public static EnvConfPathEnum getEnvConfPath(){
        return Arrays.stream(EnvConfPathEnum.values()).filter(p->p.getOsName().equals(osName)).collect(Collectors.toList()).get(0);
    }

    /**
     * 获取工程目录
     * @return
     */
    public static BasePathEnum getBaseProjectPath(){
        OSNameEnum osType = getOSType();
        BasePathEnum result = BasePathEnum.BASE_PATH_ENUM_PROJECT_PATH_MAC;
        switch (osType){
            case OS_NAME_LINUX:
                result = null;
                break;
            case OS_NAME_MAC:
                result = BasePathEnum.BASE_PATH_ENUM_PROJECT_PATH_MAC;
                break;
            case OS_NAME_WINDOWS_10:
                result = BasePathEnum.BASE_PATH_ENUM_PROJECT_PATH_WINDOWS_10;
                break;
                default: break;
        }
        return result;
    }

    /**
     * 获取用户临时目录
     * @return
     */
    public static BasePathEnum getUserTempPath(){
        OSNameEnum osType = getOSType();
        BasePathEnum result = BasePathEnum.BASE_PATH_ENUM_USER_PATH_MAC;
        switch (osType){
            case OS_NAME_LINUX:
                result = null;
                break;
            case OS_NAME_MAC:
                result = BasePathEnum.BASE_PATH_ENUM_USER_PATH_MAC;
                break;
            case OS_NAME_WINDOWS_10:
                result = BasePathEnum.BASE_PATH_ENUM_USER_PATH_WINDOWS_10;
                break;
            default: break;
        }
        return result;
    }

    public static String getOsName() {
        return osName;
    }
}
